﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

public partial class Member_MyFavourite : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            GetLVData();
        }
    }
    void GetLVData()
    {
        lvFavourite.DataSource = Profile.grpFav.Items;
        lvFavourite.DataBind();
    }
    protected void lvFavourite_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        switch (e.CommandName)
        {
            case "PrdtDel":
                {
                    Profile.grpFav.RemoveItem(e.CommandArgument.ToString());
                    Profile.Save();
                    GetLVData();
                } break;
            case "PrdtBuy":
                {
                    ListViewItem lvi=e.Item;
                    Profile.grpShoppingCart.MyCart.AddToCart(new CartItem(e.CommandArgument.ToString(), ((LinkButton)lvi.FindControl("btnPrdtName")).Text, Convert.ToDecimal(((Label)lvi.FindControl("lblPrice")).Text), 1));
                    Profile.grpFav.RemoveItem(e.CommandArgument.ToString());
                    Profile.Save();
                    GetLVData();
                    GoShopping.Utility.MessageBox.Show(this, "已加入购物车");
                    Response.Redirect("~/ShoppingCart.aspx");
                } break;
            case "ConBuy":
                {
                    Response.Redirect("~/Index.aspx");
                } break;
            default: break;
        }        
    }
    protected void lvFavourite_PagePropertiesChanging(object sender, PagePropertiesChangingEventArgs e)
    {
        ((DataPager)(this.lvFavourite.FindControl("DataPager1"))).SetPageProperties(e.StartRowIndex, e.MaximumRows, false);
        GetLVData();

    }
    protected void lvFavourite_ItemDataBound(object sender, ListViewItemEventArgs e)
    {
        ListViewItem lvi = e.Item;
        LinkButton btnDel = lvi.FindControl("btnDel") as LinkButton;
        if (btnDel != null)
        {
            btnDel.Attributes.Add("onclick", "return confirm('确定删除吗?')");
        }
    }
    private void BindListView()
    {
        
    }
}
